Skip to content

Conversation

@KuznetsovRoman
Copy link
Member

@KuznetsovRoman KuznetsovRoman commented Feb 6, 2025

@KuznetsovRoman KuznetsovRoman force-pushed the TESTPLANE-439.story_override_story_configs branch 4 times, most recently from 25e007b to dea2030 Compare February 6, 2025 23:30
@KuznetsovRoman KuznetsovRoman force-pushed the TESTPLANE-439.story_override_story_configs branch from dea2030 to f01ca4d Compare February 6, 2025 23:43
@KuznetsovRoman KuznetsovRoman force-pushed the TESTPLANE-439.story_override_story_configs branch from a654a6f to 1ba50d6 Compare February 7, 2025 17:14
"eslint": "^7.32.0",
"eslint-config-gemini-testing": "^3.0.0",
"jest": "^27.5.1",
"jest": "^29.7.0",
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Old jest didn't knew about "structuredClone" or "satisfies"

Comment on lines +26 to +27
const rawAutoScreenshotGlobalSets = extractInheritedValue(
story.autoScreenshotStorybookGlobals,
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here story.autoScreenshotStorybookGlobals is Inheritable<AutoScreenshotStorybookGlobals>

More about Inheritable at inheritable-values.ts

Comment on lines +4 to +8
// Acts like "Object.assign", but:
// - Does not mutate arguments
// - Supports functions (previousValue) => nextValue
// eslint-disable-next-line @typescript-eslint/no-explicit-any
export function inheritValue<T extends Record<any, any>>(
Copy link
Member Author

@KuznetsovRoman KuznetsovRoman Feb 7, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is used to mix functions and objects to calculate result value.

So, if you have:

  • Object Zero
  • Object A
  • Function B
  • Object C
  • Function D

inheritValue(A, B, C, D) would work this way:

  • Object A would be merged with Object Zero (with Object A having higher priority)
  • Object A would be passed into Function B
  • Its result will be merged with Object C (with Object C having higher priorify)
  • Its result will be passed into Function D
  • At the end we would receive a function, which receives Object Zero and returns merged object, while keeping Object Zero, Object A and Object C untouched

inheritValue(A, C) would simply return object, just like Object.assign(A,C)

extractInheritedValue is a funciton, which receives result of inheritValue and Object Zero in order to create result object

  • Object Zero is value from plugin's config
  • Object A / Function B is a value from storyfile's default export
  • Object C / Function D is a value from storyfile's named export

Comment on lines +64 to +69
story.autoScreenshotStorybookGlobals =
inheritValue(
storyExtendedBaseConfig.autoScreenshotStorybookGlobals,
storyTestplaneDefaultConfigs.autoScreenshotStorybookGlobals,
storyTestlaneConfigs.autoScreenshotStorybookGlobals,
) || {};
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now, when we have multiple layers of overriding, its important that these values can't be mutated.

With "autoScreenshotStorybookGlobals can be a function" (which is required to be able to overwrite without overriding), it can no longer be done with just "Object.assign", so i made "./inheritable-values.ts" module, which resolves the problem

expect(extendedStories[0].browserIds).toBe(null);
});

it("should overlay story configs / file confifs / default configs", () => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it would be better to split asserts about default/story config
current check is too difficult to understand right now

@KuznetsovRoman KuznetsovRoman force-pushed the TESTPLANE-439.story_override_story_configs branch from 12ec028 to 9442716 Compare March 6, 2025 13:50
@KuznetsovRoman KuznetsovRoman force-pushed the TESTPLANE-439.story_override_story_configs branch from 9442716 to 3a94059 Compare March 6, 2025 13:58
@KuznetsovRoman KuznetsovRoman merged commit 5246ffd into master Mar 6, 2025
2 checks passed
@KuznetsovRoman KuznetsovRoman deleted the TESTPLANE-439.story_override_story_configs branch March 6, 2025 13:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants